<template>
  <input type="file" accept=".xlsx" @change="onload" ref="ipt" />
</template>
<script>
import XLSX from 'xlsx'

export default {
  name: 'LoadFile',
  data() {
    return {
      files: undefined,
    }
  },
  props: ['value'],
  methods: {
    onload(e) {
      var reader = new FileReader()
      reader.onload = (e) => {
        const wb = XLSX.read(e.target.result, { type: 'binary' })
        const wsname = wb.SheetNames[0]
        const ws = wb.Sheets[wsname]
        const data = XLSX.utils.sheet_to_json(ws)
        this.$emit('input', data)
      }
      reader.readAsBinaryString(e.target.files[0])
    },
    onRemove() {
      this.$refs.ipt.value = ''
    },
  },
}
</script>
